package com.gaogzhen.algorithm.leetCode;

public class FindMin {
    public static void main(String[] args) {
        int[] nums = {5, 23, 44, 1, 3, 4};
        System.out.println(findMin(nums));
    }

    public static int findMin(int[] nums) {
        int left = 0, right = nums.length - 1;

        while (left < right) {
            int mid = left + (right  - left) / 2;
//            if (nums[mid] < nums[right])
//                right = mid;
//            else
//                left = mid + 1;
            if (nums[left] < nums[mid])
                right = mid;
            else
                left = mid + 1;

        }

        return nums[left];
    }

    public static int findMin1(int[] nums) {
        int len = nums.length;
        for(int i = 0; i < len - 1; i++) {
            if(nums[i] > nums[i+1])
                return nums[i+1];
        }
        return nums[0];
    }

}
